package com.mlamp;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.api.common.functions.MapFunction;

@Slf4j
public class WxLogMap implements MapFunction<String, WxLogVo> {


    @Override
    public WxLogVo map(String data) throws Exception {
        try {
            WxLogVo wxLogVo =  JSONObject.parseObject(data, WxLogVo.class);
            String appType = wxLogVo.getApp();

            String wxType = "";
            if(appType != null && appType.contains(WxLogConstant.ENTERPRICE_WECHAT)){
                wxType = WxLogConstant.ENTERPRICE_WECHAT_EN;
            }
            if(appType != null && appType.contains(WxLogConstant.WECHAT) && "".equals(wxType)){
                wxType = WxLogConstant.WECHAT_EN;
            }
            wxLogVo.setDataType(wxType);
            if(wxLogVo.getRecordDate() != null){
                wxLogVo.setTs(wxLogVo.getRecordDate());
            }
            //String location = wxLogVo.getLocation().split("/")[3];
            wxLogVo.setLocation("location");
            return wxLogVo;
        }catch (Exception e){
            e.printStackTrace();
            log.error("data parse error {} data: {}", e, data);
        }
        return null;
    }
}
